<?php

namespace App\Http\Controllers\Admin;

use App\Http\Services\KnowledgeService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class KnowledgeController extends Controller
{
    /**
     *问题详情
     * @author: lican<364548233@qq.com>
     */
    public function detail(Request $request){
        $id = $request->input('id'); //获取知识id
        $keyword = trim($request->input('keyword'));
        $data = KnowledgeService::getById($id, $keyword);
        return view('admin.knowledge.detail', compact('data'));
    }

    /**
     *知识内容
     * @author: lican<364548233@qq.com>
     */
    public function content(Request $request){
        $type = $request->input('type') ?? 0;
        $keyword = $request->input('keyword') ?? '';
        $key = 'search_params';
        $params = $type.'/'.$keyword;
        app('redis')->setex($key, 86400, $params);
        $res = KnowledgeService::list($type, $keyword);
        $list = $res['list'];
//        print_r($list);die;
        if($list){
            return view('admin.knowledge.content', compact('list', 'type', 'keyword'));
        }
    }

    /**
     *知识列表
     * @author: lican<364548233@qq.com>
     */
    public function index(Request $request){
        $params = app('redis')->get('search_params');
        $params = explode('/', $params);
        $type = isset($params[0]) ? $params[0] : 0;
        $keyword = isset($params[1]) ? $params[1] : '';
        $res = KnowledgeService::list($type, $keyword);
        $brief = $res['brief'];
        $list = $res['list'];
        return view('admin.knowledge.knowledge', compact('brief', 'list', 'type', 'keyword'));
    }

}
